package com.ruoyi.wmsorder.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysLogininfor;
import com.ruoyi.wmsorder.domain.vo.WmsPurchaseorderPoPVO;
import com.ruoyi.wmsorder.domain.vo.WmsPurchaseorderVO;
import com.ruoyi.wmsorder.domain.vo.WmsPurchaseorderVOS;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wmsorder.domain.WmsPurchaseorder;
import com.ruoyi.wmsorder.service.IWmsPurchaseorderService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购订单Controller
 * 
 * @author ruoyi
 * @date 2024-03-12
 */
@RestController
@RequestMapping("/order/purchaseorder")
public class WmsPurchaseorderController extends BaseController
{
    @Autowired
    private IWmsPurchaseorderService wmsPurchaseorderService;

    /**
     * 查询采购订单列表
     */
    @PreAuthorize("@ss.hasPermi('order:purchaseorder:list')")
    @GetMapping("/list")
    public TableDataInfo list(WmsPurchaseorder wmsPurchaseorder)
    {
        startPage();

        PageDomain pageDomain = new PageDomain();
    pageDomain.setOrderByColumn("create_time");
    pageDomain.setIsAsc("desc");
        List<WmsPurchaseorderVO> list = wmsPurchaseorderService.selectWmsPurchaseorderList(wmsPurchaseorder);

//        pageDomain.getOrderBy();
        return getDataTable(list);
    }
 /**
     * 查询采购订单弹窗列表
     */
    @PreAuthorize("@ss.hasPermi('order:purchaseorder:popList')")
    @GetMapping("/popList")
    public TableDataInfo popList(WmsPurchaseorder wmsPurchaseorder)
    {
        startPage();

        List<WmsPurchaseorderPoPVO> list = wmsPurchaseorderService.selectWmsPurchaseorderPopList(wmsPurchaseorder);
        return getDataTable(list);
    }

    /**
     * 导出采购订单列表
     */
    @PreAuthorize("@ss.hasPermi('order:purchaseorder:export')")
    @Log(title = "采购订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response)
    {
        List<WmsPurchaseorderVOS> vos = wmsPurchaseorderService.selectOrderList();
        ExcelUtil<WmsPurchaseorderVOS> util = new ExcelUtil<WmsPurchaseorderVOS>(WmsPurchaseorderVOS.class);
        util.exportExcel(response, vos, "采购订单");
    }

    /**
     * 获取采购订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:purchaseorder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {

        System.out.println("ididiidiidii = " + id);
        return success(wmsPurchaseorderService.selectWmsPurchaseorderById(id));
    }

    /**
     * 新增采购订单
     */
    @PreAuthorize("@ss.hasPermi('order:purchaseorder:add')")
    @Log(title = "采购订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsPurchaseorder wmsPurchaseorder)

    {

        wmsPurchaseorder.setCreateById(getUserId());
        wmsPurchaseorder.setUpdateById(getUserId());
        return toAjax(wmsPurchaseorderService.insertWmsPurchaseorder(wmsPurchaseorder));
    }

    /**
     * 修改采购订单
     */
    @PreAuthorize("@ss.hasPermi('order:purchaseorder:edit')")
    @Log(title = "采购订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsPurchaseorder wmsPurchaseorder)
    {

        wmsPurchaseorder.setUpdateById(getUserId());
        return toAjax(wmsPurchaseorderService.updateWmsPurchaseorder(wmsPurchaseorder));
    }

    /**
     * 删除采购订单
     */
    @PreAuthorize("@ss.hasPermi('order:purchaseorder:remove')")
    @Log(title = "采购订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wmsPurchaseorderService.deleteWmsPurchaseorderByIds(ids));
    }
}
